﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;

namespace University.Workshop.WinApp.Sale
{
    public partial class ProductSuggestionView : Form
    {
        private string search;

        public ProductSuggestionView()
        {
            InitializeComponent();
        }

        public ProductSuggestionView(string suggestionProduct)
        {
            this.search = suggestionProduct;
            InitializeComponent();
        }

        private void ProductSuggestionView_Load(object sender, EventArgs e)
        {
            dataGridViewSuggestionProduct.DataSource = SaleController.SuggestionProduct("%" + this.search + "%");
        }

        private void dataGridViewSuggestionProduct_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DataTable res;
            res=new DataTable();
            Model.Product pro = new Model.Product();
            DataGridViewRow dr = dataGridViewSuggestionProduct.Rows[dataGridViewSuggestionProduct.CurrentCell.RowIndex];
            pro.CodeProduct = dr.Cells[0].Value.ToString();
            pro.NameProduct = dr.Cells[1].Value.ToString();
            res=ProductController.GetPresentation(dr.Cells[2].Value.ToString());
            pro.Presentation = res.Rows[0].ItemArray[0].ToString();
            pro.CodeProvider = dr.Cells[3].Value.ToString();
            pro.Description = dr.Cells[4].Value.ToString();
            pro.PrescriptionMedic = dr.Cells[5].Value.ToString();
            Model.Product.Instance = pro;
            this.Close();
        }
    }
}
